package Classes.GameUtils
{
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.events.MouseEvent;
	/**
	 *把fl中的button转换成MovieClip后，在代码中模拟button 
	 * @author 邓坚
	 * 
	 */
	public class GU_btnToMC
	{
		public function GU_btnToMC()
		{
			
		}
		
		public static function addListener(mc:MovieClip):void
		{
			if(mc==null)return;
			mc.buttonMode	=	true;
			mc.gotoAndStop(1);
			mc.addEventListener(MouseEvent.MOUSE_OVER,MouseOver);
			mc.addEventListener(MouseEvent.MOUSE_OUT,MouseOut);
			mc.addEventListener(MouseEvent.MOUSE_DOWN,MouseDown);
			mc.addEventListener(MouseEvent.MOUSE_UP,MouseUp);
			mc.addEventListener(Event.REMOVED_FROM_STAGE,removeListener);
		}
		
		public static function removeListener(e:Event):void
		{
			var mc:MovieClip	=	e.currentTarget as MovieClip;
			mc.addEventListener(MouseEvent.MOUSE_OVER,MouseOver);
			mc.addEventListener(MouseEvent.MOUSE_OUT,MouseOut);
			mc.addEventListener(MouseEvent.MOUSE_DOWN,MouseDown);
			mc.addEventListener(MouseEvent.MOUSE_UP,MouseUp);
		}
		
		public static function MouseOver(e:Event):void
		{
			(e.currentTarget as MovieClip).gotoAndStop(2);
		}
		
		public static function MouseOut(e:Event):void
		{
			(e.currentTarget as MovieClip).gotoAndStop(1);
		}
		
		public static function MouseDown(e:Event):void
		{
			(e.currentTarget as MovieClip).gotoAndStop(3);
		}
		public static function MouseUp(e:Event):void
		{
			(e.currentTarget as MovieClip).gotoAndStop(2);
		}
		
	}
}